﻿using System.Linq;
using System.Reflection;

namespace Web7.Ioc
{
    public class DependencyRegistery
    {
        private IDependencyInjector dependencyInjector;

        public DependencyRegistery(IDependencyInjector dependencyInjector)
        {
            this.dependencyInjector = dependencyInjector;   
        }

        public void RegisteAssembly(Assembly assembly)
        {
            var types = from t in assembly.GetTypes()
                             where t.IsClass && !t.IsAbstract && t.IsAssignableFrom(typeof(IDependency))
                             select t;

            foreach (var item in types)
            {
                foreach(var it in item.GetInterfaces().Where(t=>t.IsAssignableFrom(typeof(IDependency))))
                {
                    dependencyInjector.RegisterType(item,it);
                }
            }
        }
    }
}
